package com.ruoyi.passenger.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.model.LoginDriver;
import com.ruoyi.system.api.model.LoginPassenger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.passenger.domain.VehiclePassenger;
import com.ruoyi.passenger.service.IVehiclePassengerService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 乘客管理Controller
 * 
 * @author ruoyi
 * @date 2023-06-26
 */
@RestController
@RequestMapping("/passenger")
public class VehiclePassengerController extends BaseController
{
    @Autowired
    private IVehiclePassengerService vehiclePassengerService;

    /**
     * 查询乘客管理列表
     */
    @RequiresPermissions("passenger:passenger:list")
    @GetMapping("/list")
    public TableDataInfo list(VehiclePassenger vehiclePassenger)
    {
        startPage();
        List<VehiclePassenger> list = vehiclePassengerService.selectVehiclePassengerList(vehiclePassenger);
        return getDataTable(list);
    }

    /**
     * 导出乘客管理列表
     */
    @RequiresPermissions("passenger:passenger:export")
    @Log(title = "乘客管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehiclePassenger vehiclePassenger)
    {
        List<VehiclePassenger> list = vehiclePassengerService.selectVehiclePassengerList(vehiclePassenger);
        ExcelUtil<VehiclePassenger> util = new ExcelUtil<VehiclePassenger>(VehiclePassenger.class);
        util.exportExcel(response, list, "乘客管理数据");
    }

    /**
     * 获取乘客管理详细信息
     */
    @RequiresPermissions("passenger:passenger:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vehiclePassengerService.selectVehiclePassengerById(id));
    }

    /**
     * 新增乘客管理
     */
    @RequiresPermissions("passenger:passenger:add")
    @Log(title = "乘客管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehiclePassenger vehiclePassenger)
    {
        return toAjax(vehiclePassengerService.insertVehiclePassenger(vehiclePassenger));
    }

    /**
     * 修改乘客管理
     */
    @RequiresPermissions("passenger:passenger:edit")
    @Log(title = "乘客管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehiclePassenger vehiclePassenger)
    {
        return toAjax(vehiclePassengerService.updateVehiclePassenger(vehiclePassenger));
    }

    /**
     * 删除乘客管理
     */
    @RequiresPermissions("passenger:passenger:remove")
    @Log(title = "乘客管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vehiclePassengerService.deleteVehiclePassengerByIds(ids));
    }

    /**
     *根据手机号查询用户是否存在
     */
    @GetMapping("getDataByMobile/{mobile}")
    public LoginPassenger getDataByMobile(@PathVariable String mobile){
        return vehiclePassengerService.getDataByMobile(mobile);
    }

    @PostMapping("register")
    public LoginPassenger register(@RequestBody LoginPassenger LoginPassenger){
        return vehiclePassengerService.register(LoginPassenger);
    }
}
